package site.isscloud.jt809;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class LoginResponse {
    public static final byte SUCCESS = 0x00;
    public static final byte FAILURE = 0x01;
    
    private byte result;        // 1字节
    private int verifyCode;     // 4字节
    
    public LoginResponse(byte result, int verifyCode) {
        this.result = result;
        this.verifyCode = verifyCode;
    }
    
    // 从字节数组解析
    public LoginResponse(byte[] data) {
        ByteBuffer buffer = ByteBuffer.wrap(data).order(ByteOrder.BIG_ENDIAN);
        this.result = buffer.get();
        this.verifyCode = buffer.getInt();
    }
    
    // 转换为字节数组
    public byte[] toByteArray() {
        ByteBuffer buffer = ByteBuffer.allocate(1 + 4)
                .order(ByteOrder.BIG_ENDIAN);
        buffer.put(result);
        buffer.putInt(verifyCode);
        return buffer.array();
    }
    
    // Getters
    public byte getResult() { return result; }
    public int getVerifyCode() { return verifyCode; }
    
    public boolean isSuccess() {
        return result == SUCCESS;
    }
}
